﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlTypes;

namespace ManWebRole.Models
{
    public class ProjectModel
    {
        private SkySRMDBDataDataContext db = new SkySRMDBDataDataContext();

        public IEnumerable<Project> GetAllProjects()
        {
            return db.Projects;
        }

        public Project GetProjectById(int id)
        {
            return db.Projects.SingleOrDefault(a => a.Id == id);
        }

        public void AddProject(Project project)
        {
           project.StartTime = DateTime.Now;
            db.Projects.InsertOnSubmit(project);
            db.SubmitChanges();
        }

        public void DeleteProjectById(int id)
        {
            Project project = GetProjectById(id);
            db.Projects.DeleteOnSubmit(project);
            db.SubmitChanges();
        }

        public void UpdateProject(Project project)
        {
            Project oldProject = GetProjectById(project.Id);
            oldProject.Name = project.Name;
            db.SubmitChanges();
        }
    }
}